package wowcatsim.view;

import wowcatsim.Simulator;
import wowcatsim.interfaces.CatStrategy;
import wowcatsim.interfaces.SimulatorView;

public class SimCmdline implements SimulatorView {

    @Override
    public void log(String line) {
        System.out.println(line);
    }

    @Override
    public void showResult(double dps, double stddev, double stderr) {
        System.out.println("Average DPS: " + dps);
        System.out.println("Std Deviation: " + stddev);
        System.out.println("Std Error: " + stderr);
    }

    @Override
    public void updateProgress(int runs, int maxruns) {
        System.out.print(runs + " of " + maxruns + " completed\r");
    }

    public static void main(String[] args) throws Exception {
        if (args.length > 0) {
            CatStrategy strat = null;
            try {
                strat = (CatStrategy) Class.forName(args[0]).newInstance();
            } catch (ClassNotFoundException e) {
                try {
                    strat = (CatStrategy) Class.forName("wowcatsim.strategy." + args[0]).newInstance();
                } catch (ClassNotFoundException ex) {
                    System.err.println("Strategy Class " + args[0] + " not found");
                }
            }
            Simulator sim = new Simulator(new SimCmdline());
            sim.setStrategy(strat);
            if (args.length > 1) {
                sim.setRuns(Integer.parseInt(args[1]));
            }
            sim.start();
        } else {
            System.out.println("Usage: SimCmdline <strategy> [runs]");
        }
    }
}
